#include "../comm.h"
class Solution {
public:
    int getWinner(vector<int>& arr, int k) {
        if(k >= arr.size() - 1)
            return *max_element(arr.begin(), arr.end());
        else
        {
            auto pos = max_element(arr.begin(), arr.begin() + k + 1);
            int now = distance(pos, arr.begin() + k + 1);
            int ans = *pos;
            int i = k + 1;
            while(now < k && i < arr.size())
            {
                int e = arr[i];
                if(arr[i] < ans)
                    ++now;
                else
                    ans = arr[i], now = 1;
                ++i;
            }
            return ans;
        }
    }
};